<template>
	<view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		}
	}
</script>

<style lang="scss">

</style>
<template>
	<view>
		<view class="goods_item" v-for="(item, index) in goods_list" :key="index" @click="toGoodDetails(item.goods_id)">
			<view class="goods_item_left">
				<image :src="item.goods_small_logo"mode="widthFix"></image>
			</view>
			<view class="goods_item_right">
				<text class="good_name">{{item.goods_name}}</text>
				<text class="good_price">￥{{item.goods_price | tofixed}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				query: {
					query: '',
					cid: '',
					pagenum : 1,
					pagesize: 10,
				},
				goods_list: [],
				isLoading: false,
				total: 0
			}
		},
		onLoad(options) {
			console.log(options)
			this.query.query = options.cid
			this.getGoodsList()
		},
		filters: {
			tofixed: function(value) {
				return Number(value).toFixed(2);
			}
		},
		methods: {
			async getGoodsList(cb) {
				this.isLoading = true
				const { data } = await uni.$http.get('/api/public/v1/goods/search', this.query)
				this.goods_list.push(...data.message.goods)
				cb && cb()
				this.total = data.message.total
				this.query.pagenum = data.message.pagenum
				this.isLoading = false
			},
			toGoodDetails(id) {
				uni.navigateTo({
					url: '/subpkg/goods_detail/goods_detail?goods_id=' + id
				})
			}
		},
		onReachBottom() {
			if (this.query.pagenum * this.query.pagesize >= this.total) return uni.showMsg('没有更多了')
			if (!this.isLoading) {
				this.query.pagenum = this.query.pagenum - 0 + 1
				this.getGoodsList()
			}
		},
		onPullDownRefresh() {
			this.query = {
				query: '',
				cid: '',
				pagenum : 1,
				pagesize: 10,
			}
			this.goods_list = []
			this.getGoodsList(() => uni.stopPullDownRefresh())
		}
	}
</script>

<style lang="scss">
.goods_item {
	display: flex;
	height: 120px;
	margin: 10px;
	border-bottom: 1px solid #EBEEF5
}
.goods_item_left {
	flex: 1;
	image {
		width: 100px;
		height: 100px;
	}
}
.goods_item_right {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	flex: 2;
	padding:10px 20px;
	.good_name {
		white-space: normal;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		overflow: hidden;
		-webkit-line-clamp: 3;
		font-size: 14px;
	}
	// .good_price {
	// 	color: #c00000;
	// 	font-size: 18px;
	// }
}
</style>
